<template>
  <Tabs :animated="false" v-model="activeTab" @on-click="handleTabClick">
    <TabPane label="用户信息" name="name1">
      <div style="display: flex;">
        <div>基础信息</div>
        <div style="width: 100px">快速更新</div>
      </div>
    </TabPane>
  </Tabs>
</template>

<script>
import axios from "axios";

export default {
  name:'UserDetails',
  inject:['reload'],

  data() {
    return {
      activeTab: this.$route.query.tab, // 设置默认的选项卡
      company: this.$route.query.company, // 获取company参数
      id: null,
      total:0, //总数据条数
      currentPage: 1, // 当前页码
      keyword:'',
    };
  },
  mounted() {
    this.getServiceData();
    this.getHostsData();
    this.getvulnerability();
    console.log('tab',this.activeTab)
  },
  methods: {
    //源数据导出
    exportData (type) {
      if (type === 1) {
        // 发送请求获取所有数据
        axios.get(`http://172.30.53.223:8888/export?company=${this.company}`,{
          responseType: 'blob' // 指定响应类型为 blob
        })
            .then(function(response) {
              // 创建一个临时链接
              const url = URL.createObjectURL(response.data);

              // 创建一个隐藏的 a 标签，设置下载链接
              const a = document.createElement('a');
              a.href = url;
              a.download = '服务列表.xlsx';

              // 点击下载链接
              a.click();

              // 释放链接资源
              URL.revokeObjectURL(url);
            })
            .catch(function(error) {
              console.error('导出失败:', error);
            });
      }
    },
    handlePageChange(currentPage){
      // 当页码变化时，更新currentPage并重新获取表格数据
      this.currentPage = currentPage;
      this.getServiceData();
    },
    handleRowClick(currentRow) {
      this.id = currentRow.id
    },
    background(type) {
      this.$Message[type]({
        background: true,
        content: type === 'success' ? '添加成功' : '添加失败'
      });
    },
    handleTabClick(tab) {
      this.activeTab = tab; // 点击选项卡时更新当前的选项卡
      this.$router.push(`/dashboard/projectlist/projectdetails?company=${this.company}&tab=${tab}`);
    },
  }
}
</script>
